
/**
 *
 * @author Evgen
 */
import java.util.Comparator;

public class Point implements Comparable<Point>
{
   // compare points by slope
   public final Comparator<Point> SLOPE_ORDER = new SlopeComparator();

   private final int x;

   private final int y;                              // y coordinate

   // create the point (x, y)
   public Point(int x, int y)
   {
      /* DO NOT MODIFY */
      this.x = x;
      this.y = y;
   }

   // plot this point to standard drawing
   public void draw()
   {
      /* DO NOT MODIFY */
      StdDraw.point(x, y);
   }

   // draw line between this point and that point to standard drawing
   public void drawTo(Point that)
   {
      /* DO NOT MODIFY */
      StdDraw.line(this.x, this.y, that.x, that.y);
   }

   // slope between this point and that point
   public double slopeTo(Point that)
   {
      if (that.x == this.x)
      {
         if (that.y == this.y) return Double.NEGATIVE_INFINITY;

         return Double.POSITIVE_INFINITY;
      }
      if (that.y == this.y) return 0.0;

      return ((double) that.y - (double) this.y) / ((double) that.x - (double) this.x);
   }

   // is this point lexicographically smaller than that one?
   // comparing y-coordinates and breaking ties by x-coordinates
   public int compareTo(Point that)
   {
      if (this.y < that.y || (this.y < that.y && this.x < that.x))
      {
         return -1;
      }
      else if (this.y == that.y && this.x == that.x)
      {
         return 0;
      }

      return 1;
   }

   // return string representation of this point
   public String toString()
   {
      /* DO NOT MODIFY */
      return "(" + x + ", " + y + ")";
   }

   // unit test
   public static void main(String[] args)
   {
      /* YOUR CODE HERE */
   }

   private class SlopeComparator implements Comparator<Point>
   {
      public int compare(Point p1, Point p2)
      {
         double res = slopeTo(p1) - slopeTo(p2);
         if (res < 0.0) return -1;
         else if (res > 0.0) return 1;
         else return 0;
      }
   }
}
